local skel = fk.CreateSkill {
  name = "emo__jinbu",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__jinbu"] = "进步",
  [":emo__jinbu"] = "锁定技，每当于出牌阶段使用有点数的牌时，若比上一张：大，摸一张牌；小，视为对自己使用【杀】。",
  ["@emo__jinbu-phase"] = "进步",

  ["$emo__jinbu1"] = "我太想进步了",
  ["$emo__jinbu2"] = "",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.extra_data and data.extra_data.emo__jinbu
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.extra_data.emo__jinbu == "draw" then
      player:drawCards(1, skel.name)
    else
      local slash = Fk:cloneCard("slash")
      slash.skillName = skel.name
      room:useCard{
        from = player, tos = {player}, card = slash, extraUse = true,
      }
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true) and player.phase == Player.Play and data.card.number > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local last = player:getMark("@emo__jinbu-phase")
    local num = data.card.number
    room:setPlayerMark(player, "@emo__jinbu-phase", num)
    if last == 0 or last == num then return end
    data.extra_data = data.extra_data or {}
    if num > last then
      data.extra_data.emo__jinbu = "draw"
    else
      data.extra_data.emo__jinbu = "slash"
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@emo__jinbu-phase", 0)
end)

skel:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  if player.phase == Player.Play then
    local parent = player.room.logic:getCurrentEvent():findParent(GameEvent.Phase, true)
    if parent == nil then return end
    player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
      local use = e.data
      if use.from == player and use.card.number > 0 then
        room:setPlayerMark(player, "@emo__jinbu-phase", use.card.number)
        return true
      end
    end, parent.id)
  end
end)

return skel
